package com.egao.common.publicly;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.egao.common.core.web.JsonResult;
import com.egao.common.module.marketPush.entity.MarketPush;
import com.egao.common.module.marketPush.entity.MarketPushRecord;
import com.egao.common.module.marketPush.service.MarketPushRecordService;
import com.egao.common.module.marketPush.service.MarketPushService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author lym
 * @date 2024/5/28 21:55
 */
@Api(tags = "公开就业推送信息")
@RestController
@RequestMapping("${api}")
public class PubliclyMarketPushController {

    @Autowired
    private MarketPushService marketPushService;
    @Autowired
    private MarketPushRecordService marketPushRecordService;

    @ApiOperation("详情")
    @GetMapping("/publicly/market-push/get")
    public JsonResult get(Integer id, String xh) {
        if (id == null) {
            return JsonResult.error("参数异常");
        }

        MarketPush marketPush = marketPushService.getById(id);
        if (marketPush == null) {
            return JsonResult.error("信息不存在");
        }

        marketPushRecordService.update(new LambdaUpdateWrapper<MarketPushRecord>()
                .set(MarketPushRecord::getReadState, "0")
                .set(MarketPushRecord::getReadTime, new Date())
                .eq(MarketPushRecord::getMarketPushId, id)
                .eq(MarketPushRecord::getXh, xh)
        );


        return JsonResult.ok().setData(marketPush);
    }
}
